<?php

/*
Zoo Management Simulation
This file edits the database by updating the entry table or deleting an entry record based on user actions on a previous file
*/

include("dbconnect.php");
if ($_REQUEST['submit'] === "Return to Administator page"){
	header('Location: index.php');
}

$numEntries = $_REQUEST['numentry'];
$entry = 1;
$entrynumber = 1;
$cageid = $_REQUEST['cageid'];
$entryid = $_REQUEST['entryid'];

if ($_REQUEST['submit'] === "Delete"){
	$deleteentrysql = "DELETE FROM `entry` WHERE Entry_Id='".$entryid."'";
	$deleteresult = mysql_query($deleteentrysql);
}

else if ($_REQUEST['submit'] === "Edit Cage Entries"){
$idSql = "SELECT Entry_Id FROM entry WHERE Cage_Id=".$cageid;
$idResult = mysql_query($idSql);
while(($row = mysql_fetch_row($idResult)) !== FALSE)
	{
		$id = $row[0];
		$doortype = $_REQUEST["doortype".$entrynumber];
		$doorstatus = $_REQUEST["doorstatus".$entrynumber];
		$entrysql = "UPDATE `entry` SET `Entry_Desc`='".$doortype."',`Entry_Status`='".$doorstatus."' WHERE Entry_Id=".$id;
		$entryResult = mysql_query($entrysql);
		$entrynumber+=1;
	}
}
header('Location: index.php');
?>